package com.isman.exec;

import java.io.File;
import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.google.appengine.repackaged.org.codehaus.jackson.map.ObjectMapper;
import com.isman.domain.Person;
import com.isman.jackson.hibernate4.Hibernate4Module;

/**
 * Hello world!
 *
 */
public class App {
	public static void main(String[] args) {
		//System.out.println("Hello World!");
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = session.beginTransaction();
		
		
		List<Person> result = session.createCriteria(Person.class).list();
		for (Person person : result) {
			Hibernate.initialize(person.getDepartment());
		}
		tx.commit();
		
		ObjectMapper mapper = new ObjectMapper();
		mapper.registerModule(new Hibernate4Module());
		
		
		try {
			mapper.writeValue(new File("D:\\user.json"), result);
			

			System.out.println(mapper.writeValueAsString(result));
		} catch (Exception e) {
			e.printStackTrace();
			
			System.err.println(e.getMessage());
		}
	}
}
